layui.define(['table', 'form', 'admin', 'upload'], function(exports) {
    var $ = layui.$
        , table = layui.table
        , form = layui.form
        , upload = layui.upload
        , admin = layui.admin;

    table.render({
        elem: '#LAY-guess-manage'
        , url: '/admin/guess/getlist'
        , cols: [[
            {field: 'id', width: 100, title: 'ID', sort: true}
            , {field: 'matchid', width: 150, title: '比赛ID'}
            , {field: '', width: 150, title: '类型', templet: function (d) {
                    var typeJ = {1: "大小球",2: "半场赛果",3: "全场赛果",4: "总得分单双",5: "上半场单双",6: "下半场单双"};
                    return typeJ[d.type];
                }}
            , {field: 'title', width: 250, title: '标题'}
            , {field: 'value', width: 100, title: '让分设置'}
            , {field: 'value1', width: 100, title: '主/大'}
            , {field: 'value2', width: 100, title: '平'}
            , {field: 'value3', width: 100, title: '客/小'}
            , {field: 'result', width: 150, title: '竞猜结果'}
            , {field: 'stop_time', minWidth: 150, title: '竞猜截止'}
        ]]
        , page: true
        , limit: 20
        , height: 'full-140'
        , text: '对不起，加载出现异常！'
        , even: true
    });

    //
    table.render({
        elem: '#LAY-guess-bymatch-manage'
        , url: '/admin/guess/getlistbymatch?matchid='+$("#matchid").val()
        , cols: [[
            {field: 'id', width: 100, title: 'ID', sort: true}
            , {field: '', width: 150, title: '类型', templet: function (d) {
                    var typeJ = {1: "大小球",2: "半场赛果",3: "全场赛果",4: "总得分单双",5: "上半场单双",6: "下半场单双"};
                    return typeJ[d.type];
                }}
            , {field: 'title', width: 250, title: '标题'}
            , {field: 'value', width: 100, title: '让分设置'}
            , {field: 'value1', width: 100, title: '主/大'}
            , {field: 'value2', width: 100, title: '平'}
            , {field: 'value3', width: 100, title: '客/小'}
            , {field: 'result', width: 150, title: '竞猜结果'}
            , {field: 'stop_time', minWidth: 150, title: '竞猜截止'}
        ]]
        , page: false
        , limit: 0
        , height: 'full-140'
        , text: '对不起，加载出现异常！'
        , even: true
    });

    //监听工具条
    table.on('tool(LAY-guess-manage)', function(obj){
        if(obj.event === 'del'){
            layer.confirm('确认删除？', function(index){
                var status = obj.data.status == 0?1:0;
                admin.req({
                    url: '/admin/guess/del_post'
                    ,data: {"id":obj.data.id}
                    ,success(res){
                        if (res.code == 0){
                            table.reload("LAY-guess-manage");
                            layer.msg(res.msg, {icon:1});
                        } else{
                            layer.msg(res.msg, {icon:5});
                        }
                    }
                });
            });
        } else if(obj.event === 'edit'){
            layer.open({
                type: 2
                ,title: '编辑'
                ,content: '/admin/guess/edit?id='+obj.data.id
                ,maxmin: true
                ,area: ['450px', '300px']
            });
        }
    });

    table.render({
        elem: '#LAY-bet-manage'
        , url: '/admin/guess/getbetlist'
        , cols: [[
            {field: 'id', width: 100, title: 'ID', sort: true}
            , {field: 'guessid', width: 150, title: '竞猜ID'}
            , {field: 'uid', width: 150, title: '用户ID'}
            , {field: 'guess_value', width: 250, title: '竞猜选项'}
            , {field: 'gold', width: 100, title: '投注数量'}
            , {field: '', width: 100, title: '是否猜中', templet:function (d) {
                    if (d.result == 0){
                        return "未出结果";
                    }
                    return d.is_hit ? "是":"否";
                }}
            , {field: 'create_time', minWidth: 150, title: '下注时间'}
        ]]
        , page: true
        , limit: 20
        , height: 'full-140'
        , text: '对不起，加载出现异常！'
        , even: true
    });


    exports('guess', {})
});